/**
 * Created by ruiyuan on 15-9-19.
 */
var Schema = mongoose.Schema;


var goodsSchema = new Schema({
    title: String,                          //标题
    desc: String,                           //描述
    images: [                               //图片
        {
            imageURL: String
        }
    ],
    presentPrice: {type: Number, default: 0},           //现价
    originalPrice: {type: Number, default: 0},          //原价
    priceOrder: Number,                                  //价格排序字段
    dealStatus: {type: Number, default: 0},             //交易状态  0,未交易;1,已交易
    type: {type: Number, default: 1},                   //1,二手 2,免费
    category: {type: Schema.Types.ObjectId, ref: 'goods_category'},  //baby、home、ornament、card、toy、other
    community: {type: Schema.Types.ObjectId, ref: 'community'}, //小区
    communityPrice: Number,
    communityDateBuild: Date,
    aroundCommunity: [                                          //周边小区
        {type: Schema.Types.ObjectId, ref: 'community', index: true}
    ],
    city: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'}, //城市
    location: {                                                     //位置
        longitude: Number,
        latitude: Number
    },
    locOrder: {
        longitude: Number,
        latitude: Number
    },
    point: String,
    isInit: {type: Number, default: 1},                             //0,未完善 1,已完善
    level: {type: Number, default: 0},                              //0,普通   1,推荐
    recDate: Date,                                                   //推荐时间
    saleNumber: Number,
    createdBy: {type: Schema.Types.ObjectId, ref: 'user'},          //创建者
    isValid: {type: Boolean, default: true},
    fromFlag: String,
    releaseDate: {type: Date, default: Date.now},                   //发布时间
    releaseNum: Number,
    dateLastModified: {type: Date, default: Date.now},              //更新时间
    dealDate: Date,                      //成交时间
    dateCreated: {type: Date, default: Date.now},                   //创建时间

    itemType: {type: Number, default: 1}       // 1:闲置，2:服务
});
goodsSchema.index({'locOrder': '2dsphere'});
goodsSchema.index({'location': '2dsphere'});
mongoose.model('goods', goodsSchema, 'goods');

var goodsReplySchema = new Schema({
    goodsId: {type: Schema.Types.ObjectId, ref: 'goods'},           //商品id
    replyDesc: String,                                              //回复内容
    community: {type: Schema.Types.ObjectId, ref: 'community'},     //小区
    repliedBy: {type: Schema.Types.ObjectId, ref: 'user'},          //回复者
    replyTo: {type: Schema.Types.ObjectId, ref: 'user'},
    quoteId: {type: Schema.Types.ObjectId, ref: 'goods_reply'},
    dateReplied: {type: Date, default: Date.now}                    //回复时间
});
mongoose.model('goods_reply', goodsReplySchema, 'goods_reply');

var goodsCategorySchema = new Schema({
    name: String,
    img: String,
    isHot: {type: Boolean, default: false},
    displayOrder: {type: Number, default: 0},
    dateCreated: {type: Date, default: Date.now},
    itemType: {type: Number, default: 1}   // 1:闲置，2:服务
});
mongoose.model('goods_category', goodsCategorySchema, 'goods_category');

var goodsQueryTermsSchema = new Schema({
    name: String,
    value: String,
    isHot: {type: Boolean, default: false},
    displayOrder: {type: Number, default: 0},
    type: Number,                   //1,范围 2,分类 3,排序 4,商品类型
    dateCreated: {type: Date, default: Date.now},
    itemType: {type: Number, default: 1}   // 1:闲置，2:服务
});
mongoose.model('goods_queryTerms', goodsQueryTermsSchema, 'goods_queryTerms');

var goodsSaleRecordSchema = new Schema({
    user: {type: Schema.Types.ObjectId, ref: 'user'},
    nickName: String,
    mobilePhone: String,
    goodsId: {type: Schema.Types.ObjectId, ref: 'goods'},
    goodsTitle: String,
    dateCreated: {type: Date, default: Date.now}
});
mongoose.model('goods_sale_userRecord', goodsSaleRecordSchema, 'goods_sale_userRecord');

/*  宝宝树66小区二次改造    add   chenf  20170821   start   追加举报区分闲置和帖子*/
//=====================question_reports==========================
var goodsReportMongoSchema = new Schema({
    goods: {type: Schema.Types.ObjectId, ref: 'goods'},
    goodsCommunity: {type: Schema.Types.ObjectId, ref: 'community'},           //goods所属小区
    goodsCreateBy : {type: Schema.Types.ObjectId, ref: 'user'},
    reportStatus : {type: Number, default: 0},                                  //-1:已忽略 0：未处理 1：已删除
    activity: {type: Schema.Types.ObjectId, ref: 'activity_neighbour'},
    reportUser: {type: Schema.Types.ObjectId, ref: 'user'},
    status: {type: Boolean, default: false},
    dateCreated: {type: Date, default: Date.now}
});
mongoose.model('goods_reports', goodsReportMongoSchema, 'goods_reports');
/*  宝宝树66小区二次改造    add   chenf  20170821   start   追加举报区分闲置和帖子*/